﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Visitor
{
    //图像的基类
    public abstract class Shape
    {
        public abstract void Draw();

        public virtual void Accept(ShapeVisitor visitor)
        {
            throw new NotImplementedException(); 
        }
    }

    //访问者抽象类
    public abstract class ShapeVisitor
    {
        public abstract void Move(Shape shape);
    }

    #region 实体类


    public class Rectangle : Shape
    {
        public override void Draw()
        {
            Console.WriteLine("开始绘制矩形");
        }

        public override void Accept(ShapeVisitor visitor)
        {
            visitor.Move(this);
        }
    }

    public class Circle : Shape
    {
        public override void Draw()
        {
            Console.WriteLine("开始绘制圆形。。");
        }
        public override void Accept(ShapeVisitor visitor)
        {
            visitor.Move(this);
        }
    }

    public class Line : Shape
    {
        public override void Draw()
        {
            Console.WriteLine("开始绘制一条直线");
        }
        public override void Accept(ShapeVisitor visitor)
        {
            visitor.Move(this);
        }
    }

    #endregion

    //实现访问者的实体类
    public class RealizeShapeVisitor : ShapeVisitor
    {
        public override void Move(Shape shape)
        {
            if (shape is Rectangle)
            {
                Console.WriteLine("矩形开始移动");
            }else if(shape is Circle)
            {
                Console.WriteLine("圆圈开始移动");
            }
            else if (shape is Line)
            {
                Console.WriteLine("一条直线开始移动");
            }
        }
    }
}
